package com.easyfile.easyfilemaster.entity.base;

/**
 * 返回结果生成工厂
 * @author Chenpeman
 */
public class ResultFactory<T> {

    public static <T> Result<T> success(){
        Result<T> result = new Result<>();
        result.setCode(RetCode.SUCCESS.code);
        result.setMsg("请求成功");
        result.setData(null);
        return result;
    }
    public static <T> Result<T> success(String msg){
        Result<T> result = new Result<>();
        result.setCode(RetCode.SUCCESS.code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(RetCode.SUCCESS.code);
        result.setMsg("请求成功");
        result.setData(data);
        return result;
    }
    public static <T> Result<T> success(T data,String msg){
        Result<T> result = new Result<>();
        result.setCode(RetCode.SUCCESS.code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(){
        Result<T> result = new Result<>();
        result.setCode(RetCode.FAIL.code);
        result.setMsg("请求失败");
        result.setData(null);
        return result;
    }
    public static <T> Result<T> fail(String msg){
        Result<T> result = new Result<>();
        result.setCode(RetCode.FAIL.code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }
    public static <T> Result<T> fail(T data){
        Result<T> result = new Result<>();
        result.setCode(RetCode.FAIL.code);
        result.setMsg("请求失败");
        result.setData(data);
        return result;
    }
    public static <T> Result<T> fail(T data,String msg){
        Result<T> result = new Result<>();
        result.setCode(RetCode.FAIL.code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> unauthorized(){
        Result<T> result = new Result<>();
        result.setCode(RetCode.UNAUTHORIZED.code);
        result.setMsg("未认证");
        result.setData(null);
        return result;
    }

    public static <T> Result<T> unauthorized(String msg){
        Result<T> result = new Result<>();
        result.setCode(RetCode.UNAUTHORIZED.code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }

    public static <T> Result<T> internalError(){
        Result<T> result = new Result<>();
        result.setCode(RetCode.INTERNAL_SERVER_ERROR.code);
        result.setMsg("服务器内部异常");
        result.setData(null);
        return result;
    }

    public static <T> Result<T> internalError(String msg){
        Result<T> result = new Result<>();
        result.setCode(RetCode.INTERNAL_SERVER_ERROR.code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }
}
